package com.hgxd.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hgxd.entity.pojo.SysRole;
import com.hgxd.entity.pojo.SysUserRole;
import com.hgxd.mapper.SysRoleMapper;
import com.hgxd.mapper.SysUserRoleMapper;
import com.hgxd.service.SysRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wtf
 */
@Service("sysRoleServiceImpl")
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Resource
    private SysUserRoleMapper sysUserRoleMapper;


    @Override
    public List<Long> getRoleByUserId(Long userId) {
        LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUserRole::getUserId,userId);
        List<SysUserRole> sysUserRoles = sysUserRoleMapper.selectList(queryWrapper);
        List<Long> list = sysUserRoles.stream()
                .map(SysUserRole::getRoleId).collect(Collectors.toList());
        return list;
    }
}
